<template>
	<view>
		<view class="cu-custom" :style="{height: $wanlshop.wanlsys().height + 'px' }">
			<view class="cu-bar fixed" :style="{
				height: $wanlshop.wanlsys().height + 'px', 
				paddingTop: $wanlshop.wanlsys().top + 'px',
				color: '#333333',
				backgroundColor: '#fff',
			}">
				<view class="action" @tap="$wanlshop.back(1)">
					<text class="wlIcon-fanhui1"></text>
				</view>
				<view class="content text-bold" :style="{top: $wanlshop.wanlsys().top + 'px'}">
					医养院服务
				</view>
				<!-- <view class="action" style="color: #4cbd66;" @click="jumpReal('/pages/Medical/list')">
					申请列表
				</view> -->
			</view>
		</view>
		<view class="top">
			<view class="topFlex">
				<view class="topFlexLeft" @click="jump('/pages/page/city')">
					<view class="topFlexLeftText">{{city}}</view>
					<view class="iconfont icon-arrow-down-filling"></view>
				</view>
				<view class="topFlexInt">
					<view class="iconfont icon-sousuo"></view>
					<input placeholder="搜索" class="int" placeholder-class="intm" @confirm='confirm' />
				</view>
				<!-- <view class="topFlexRight" @click="jumpReal('/pages/Medical/apply')">
					<view class="iconfont icon-shenqing"></view>
					<view class="topFlexRightText">申请</view>
				</view> -->
			</view>
		</view>

		<view class="list" v-if="list.length > 0"  v-for="(item,index) in list" :key="index">
			<view class="listItem"
				@click="jump('/pages/Medical/details?id='+ item.id)">
				<image :src="item.image" class="itemImg" mode="aspectFill"></image>
				<view class="itemRight">
					<view class="itemRightTitle">{{item.title}}</view>
					<view class="itemRightTitleFlex">
						<view class="iconfont icon-dingweixiao"></view>
						<view class="itemRightText">{{item.address}}</view>
					</view>
					<view class="listFlex">
						<view class="listFlexItem" v-for="(itm,idx) in item.receiver" :key='idx'>{{itm}}</view>
					</view>
					<view class="itemRightMoney">￥{{item.price}}</view>
				</view>
			</view>
		</view>
		<view class="consult" @click="jump('/pages/Medical/consultList')">
			<!-- <view style="margin-top: 20rpx;">咨询</view>
			<view>列表</view> -->
			<view style="width: 100%;margin-top: 10rpx;">咨询</view>
			<view style="width: 100%;margin-bottom: 10rpx;">列表</view>
		</view>
		<block v-if="list.length === 0 && status !== 'loading'">
			<wanl-empty :text="empty" />
		</block>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		computed: {
			...mapState(['user'])
		},
		data() {
			return {
				list: [],
				params: {
					keyword: '',
					page: 1
				},
				empty: '没有找到医养院服务',
				reload: true, //判断是否上拉
				last_page: 0,
				status: 'loading',
				contentText: {
					contentdown: '',
					contentrefresh: '正在加载..',
					contentnomore: '没有更多数据了'
				},
				city:''
			}
		},
		onShow() {
			this.city = uni.getStorageSync('city');
			if (this.$store.state.user.isLogin) {
				this.getInfo();	
			}
			this.loadData();
			
		},
		onLoad() {
			
		},
		// 下拉刷新
		onReachBottom() {
			if (this.params.page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.contentText.contentdown = '上拉显示更多';
				this.params.page = this.params.page + 1; //页码+1
				this.status = 'loading';
				this.loadData();
			}
		},
		methods: {
			async getInfo(){
				await uni.request({
					url: '/member/user/info',
					method: 'POST',
					success: res => {
						this.$store.commit('user/setUserInfo', res.data);
					}
				});
			},
			
			// 判断是否实名
			jumpReal(url){
				console.log("cxzczxcz",this.user.real_verified)
				if(this.user.real_verified == 1){
					this.$wanlshop.auth(url)
				}else{
					uni.showToast({
						title: '请先进行实名认证',
						icon: 'none',
						position: true
					});
					setTimeout(()=>{
						this.$wanlshop.auth('/pages/user/setting/verified')
					},2000)
				}
				
				// this.$wanlshop.auth('/pages/volunteer/apply')
			},
			jump(url) {
				this.$wanlshop.auth(url)
				// uni.navigateTo({
				// 	url: url
				// })
			},
			confirm(e) {
				console.log("zzzz", e)
				this.params.keyword = e.detail.value
				this.page = 1
				this.loadData()
			},
			//异步加载商品列表
			async loadData() {
				this.params.city = uni.getStorageSync('cityid')
				await uni.request({
					url: '/addons/nursing/api.index/lists',
					data: this.params,
					method: 'POST',
					success: res => {
						this.status = 'more';
						this.list = this.reload ? res.data.data : this.list.concat(res.data
							.data); //数据 追加
						if (res.data.data.length == 0) {
							this.empty = `没有找到医养院服务`;
						}
						this.params.page = res.data.current_page; //当前页码
						this.last_page = res.data.last_page; //总页码
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.top {
		width: 100%;
		height: 94rpx;
		background: #fff;

		.topFlex {
			display: flex;
			align-items: center;
			width: 690rpx;
			height: 100%;
			margin: 0 auto;

			.topFlexLeft {
				display: flex;
				align-items: center;
				color: #4CBD66;
				width: 128rpx;

				.topFlexLeftText {
					margin-right: 10rpx;
				}

				.iconfont {
					font-size: 14rpx;
				}
			}

			.topFlexInt {
				// width: 500rpx;
				flex: 1;
				height: 60rpx;
				border-radius: 30rpx;
				border: 2rpx solid #4CBD66;
				margin-left: 10rpx;
				display: flex;
				align-items: center;
				color: #4CBD66;

				.iconfont {
					margin-left: 22rpx;
				}

				.int {
					width: 400rpx;
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #4CBD66;
					margin-left: 20rpx;
				}

				.intm {
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #4CBD66;
				}
			}

			.topFlexRight {
				margin-left: auto;
				text-align: center;
				color: #4CBD66;
				font-size: 20rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;

				.topFlexRightText {
					margin-top: 10rpx;
				}
			}
		}
	}

	.list {
		width: 92%;
		height: auto;
		margin: 20rpx auto;
		background: #fff;
		border-radius: 10rpx;

		.listItem {
			padding: 18rpx;
			display: flex;

			.itemImg {
				width: 150rpx;
				height: 150rpx;
				border-radius: 10rpx;
			}

			.itemRight {
				// width: 390rpx;
				flex: 1;
				height: auto;
				margin-left: 20rpx;

				.itemRightTitle {
					font-size: 32rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #333333;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					margin-bottom: 12rpx;
				}

				.itemRightTitleFlex {
					display: flex;
					align-items: center;
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #555555;
					margin-top: 6rpx;

					.iconfont {
						font-size: 20rpx;
						color: #4CBD66;
						margin-right: 10rpx;
					}

					.itemRightText {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}


				.listFlex {
					display: flex;
					width: 100%;
					flex-wrap: wrap;

					.listFlexItem {
						padding: 2rpx 10rpx;
						border: 2rpx solid #888888;
						border-radius: 6rpx;
						margin-right: 10rpx;
						margin-top: 12rpx;
						font-size: 26rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #888888;
					}
				}

				.itemRightMoney {
					font-size: 32rpx;
					font-family: DIN-Bold, DIN;
					font-weight: bold;
					color: #E31F1F;
					margin-top: 10rpx;
				}

			}
		}
	}
	.consult {
		width: 100rpx;
		height: 100rpx;
		background: #4CBD66;
		border-radius: 100%;
		text-align: center;
		color: #fff;
		position: fixed;
		right: 10rpx;
		top: 50%;
		font-size: 22rpx;
		z-index: 99;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: center;
	}
</style>